<?php
    
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../../../Ginecobstetricia/vista/css/bootstrap-combined.min.css" rel="stylesheet">
         <!-- Librerias jquery y hojas de estilo para creacion  del calendario -->
        <script src="../../../vista/reportes/js/jquery-1.5.2.js" type="text/javascript"></script>
        <!-- LIBRERIAS JQUERY PARA LA CREACION DE LAS ALERTAS -->
        <script type="text/javascript" src="../../../Ginecobstetricia/vista/js/alertify.js"></script>
        <link rel="stylesheet" href="../../../Ginecobstetricia/vista/css/alertify.core.css" />
        <link rel="stylesheet" href="../../../Ginecobstetricia/vista/css/alertify.default.css" />
        <style>
            .white {
                border-radius: 5px;
                color: #606060;
                border: solid 1px #b7b7b7;
                background: #fff;
                background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                background: -moz-linear-gradient(top,  #fff,  #ededed);
                filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
                padding: 4px 4px 4px;
                height: 30px;
                font-size: 13px;
            }
            .white:hover {
                background: #ededed;
                background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
                background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
                filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
            }
            .white:active {
                color: #999;
                background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#fff));
                background: -moz-linear-gradient(top,  #ededed,  #fff);
                filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#ffffff');
            }
            
            /* para las filas impares */
            table tr:nth-child(odd) th {
                background-color: #DAEAFF;
                font-weight: normal;
            }
            /* para las filas paras */
            table tr:nth-child(even) th {
                background-color: #FFFFFF;
                font-weight: normal;
            }
        </style>
        <script>
            
            function cancelar(){
                document.location.reload();
            }
            function buscarD(){
                var descri = $("#buscar").val();
                    $.ajax({
                    async: true,
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url:"../../controlador/php/sql/buscarD.php",
                    data:{descri:descri},
                    success:dato,
                    timeout: 4000
                });
            }
            function dato(datos){
                $("#datosd").text("");
                rpt = $.parseJSON(datos);
                    datos = $("#datosd");
                    var resp = "";
                    resp += "<table style='font-size:90%;overflow:hidden;border:1px solid #d3d3d3;background:#fefefe;width:100%;-moz-border-radius:5px; /* FF1+ */-webkit-border-radius:5px; /* Saf3-4 */border-radius:5px;-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2); '>\
                                <tr>\
                                    <td colspan='2' style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb; '>\
                                         Descripcion\
                                    </td>\
                                    <td style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb; '>\
                                         Seleccionar\
                                    </td>\
                                    <td style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                         Editar\
                                    </td>\
                                </tr>";
                    var con = 1;
                    var descri = "";
                     for(dat in rpt){
                     descri = rpt[dat].ridescri;
                     resp += "<tr>\
                                    <th>\
                                        "+ con +"\<input type='hidden' name='txtoid[]' value="+rpt[dat].oid+" id='oid"+con+"'/>\
                                    </th>\
                                     <th align='left'>\
                                        "+ rpt[dat].ridescri +"\
                                    </th>\
                                    <th>\
                                        <input type='checkbox' name='cbseleccion[]' value='1' id='seleccionc"+ con +"' title='Seleccionar'/>\
                                    </th>\
                                    <th>\
                                        <img src='../../../vista/imagen/editar2.png' width='20' height='20' alt='editar' title='Editar' onclick='editar("+ rpt[dat].oid +","+ con +");'/><input type='hidden' id='oidr"+ con +"' name='txtoidr' value='"+ rpt[dat].oid  +"' /><input type='hidden' id='descri"+ con +"' name='txtdescri' value='"+ descri +"' />\
                                   </th>\
                                 </tr>";
                   con++;
                   } 
                   resp += "</table>";
                   datos.append(resp);
                   listaItems();
                   
                }
            function cancelarD(){
                document.getElementById("nuevoD").innerHTML='';
            }
            function nuevoD(){
               document.getElementById("nuevoD").innerHTML='<table style="font-size:90%">\
                                                               <tr>\
                                                                   <td style="width:25%">\
                                                                       Nuevo Riesgo Especifico:\
                                                                   </td>\
                                                                   <td>\
                                                                       <input type="text" name="txtnuev" value="" id="parted" style="width:80%"/>\
                                                                        <img src="../../../vista/imagen/aceptar.png" width="20" height="20" onclick="validarD();" title="guardar"/>\
                                                                        <img src="../../../vista/imagen/cancel.png" width="20" height="20" alt="agregr" onclick="cancelarD();" title="cancelar"/>\
                                                                    </td>\
                                                               </tr>\
                                                           </table>';
             }
             function validarE(oid){
                 if ($("#editard").val()===""){
                alertify.alert("Digite un riesgo especifico"), function () {
                    $("#editard").focus();
                };
                return false;
            }
            guardar(oid);
                 
             }
             function editar(oid,con){
                 document.getElementById("nuevoD").innerHTML='<table style="font-size:90%">\
                                                                <tr>\
                                                                    <td style="width:25%">\
                                                                        Editar Riesgo Especifico:\
                                                                     </td>\
                                                                     <td>\
                                                                        <input type="text" name="txtnuev" value="" id="editard" style="width:80%"/>\
                                                                        <img src="../../../vista/imagen/gc.png" width="20" height="20" title="guaradar cambios" onclick="validarE('+oid+');"/>\
                                                                        <img src="../../../vista/imagen/cancel.png" width="20" height="20" alt="agregr" title="cancelar" onclick="cancelarD();"/>\
                                                                     </td>\
                                                                </tr>\
                                                                </table>';
                 $("#editard").attr('value',document.getElementById("descri"+con).value);
                 
             }
             function guardar(oid){
                 var id = oid;
                 var descri = $("#editard").val();
                 $.ajax({
                    async: true,
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url:"../../controlador/php/sql/editarD.php",
                    data:{id:id,descri:descri},
                    success:editarD,
                    timeout: 4000
                });
                 
             } 
            function editarD(){
                document.getElementById("nuevoD").innerHTML='';
                $("#datosd").text("");
                buscarD();
            }
           function validarD(){
                 if ($("#parted").val()===""){
                alertify.alert("Digite un riesgo especifico"), function () {
                    $("#parted").focus();
                };
                return false;
            }
            parteD();
            }
            function validarBuscar(){
            if ($("#buscar").val()===""){
                alertify.alert("Digite una descripcion"), function () {
                    $("#buscar").focus();
                };
                return false;
            }
            buscarD();
            }
            function parteD(){
                var prd = $("#parted").val();
                $.ajax({
                    async: true,
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url:"../../controlador/php/sql/parteD.php",
                    data:{prd:prd},
                    success:guarda,
                    timeout: 4000
                });
            }
            function guarda(){
                document.getElementById("parted").value = "";
                $("#datosd").text("");
                datosD();
                
            }
            function confirmar(oid){
            alertify.confirm("<p>Esta seguro de elimiar el riesgo especifico</p>", function (c) {
                    if (c) {
                       eliminarD(oid);
                    }
                }); 
                return false;
               }
            /*function eliminarD(oid){
               var id = oid;
                $.ajax({
                    async: true,
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url:"../../controlador/php/sql/eliminarD.php",
                    data:{id:id},
                    success:eliminar,
                    timeout: 4000
                });
            }
            function eliminar(){
                $("#datosd").text("");
                datosD();
            }*/
            function datosD(){
                $.ajax({
                      async: true,
                     type:"POST",
                     datatype: "json",
                     contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                     url: "../../controlador/php/sql/datosD.php",
                     success: datosD2,
                     timeout: 4000 
                   });
            }
            function datosD2(datos){
                    rpt = $.parseJSON(datos);
                    datos = $("#datosd");
                    var resp = "";
                    resp += "<table style='font-size:90%;overflow:hidden;border:1px solid #d3d3d3;background:#fefefe;width:100%;-moz-border-radius:5px; /* FF1+ */-webkit-border-radius:5px; /* Saf3-4 */border-radius:5px;-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2); '>\
                                <tr>\
                                    <td colspan='2' style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb; '>\
                                         Descripcion\
                                    </td>\
                                    <td style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb; '>\
                                         Seleccionar\
                                    </td>\
                                    <td style='padding:1px 1px 1px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                         Editar\
                                    </td>\
                                </tr>";
                    var con = 1;
                    var descri = "";
                     for(dat in rpt){
                     descri = rpt[dat].ridescri;
                     resp += "<tr>\
                                    <th>\
                                        "+ con +"\<input type='hidden' name='txtoid[]' value="+rpt[dat].oid+" id='oid"+con+"'/>\
                                    </th>\
                                     <th align='left'>\
                                        "+ rpt[dat].ridescri +"\
                                    </th>\
                                    <th>\
                                        <input type='checkbox' name='cbseleccion[]' value='1' id='seleccionc"+ con +"' title='Seleccionar'/>\
                                    </th>\
                                    <th>\
                                        <img src='../../../vista/imagen/editar2.png' width='20' height='20' alt='editar' title='Editar' onclick='editar("+ rpt[dat].oid +","+ con +");'/><input type='hidden' id='oidr"+ con +"' name='txtoidr' value='"+ rpt[dat].oid  +"' /><input type='hidden' id='descri"+ con +"' name='txtdescri' value='"+ descri +"' />\
                                   </th>\
                                 </tr>";
                   con++;
                   } 
                   resp += "</table>";
                   datos.append(resp);
                   listaItems();
                   
                }
                
                function agregarD(){
                   var tama = 0;
                   var j = 0;
                   tama = document.getElementsByName("cbseleccion[]");
                   var listaoid = new Array();
                   var listades = new Array();
                   for(var i = 1; i<=tama.length ; i++){
                       if(document.getElementById("seleccionc"+i).checked == true){
                           //alert(document.getElementById("oidr"+i).value+"-"+document.getElementById("descri"+i).value);
                           listaoid[j] = document.getElementById("oidr"+i).value;
                           listades[j] = document.getElementById("descri"+i).value;
                           j++;
                       }
                   }
                   
                   window.opener.agregarItemsD(listaoid,listades,j);
                   window.close();
                   
                }
                function listaItems(){
                     /*lista de diagnosticos especificos que vienen del formulario(Plantilla Concentimiento Informado)*/
                     var pos = document.getElementById("pos").value;
                     /*variables lista1*/
                     var splt = "";
                     var oid = "";
                     var oid2 = "";
                     
                     /*variables lista2*/
                     var t = 0;
                     var oida = 0;
                     
                     for(var i = 0;i<pos;i++){
                         /*se parte la cadena  de la caja de texto sacando los oid de los diagnosticos*/
                         splt = document.getElementById("listaoid").value;
                         oid = splt.split(",");
                         oid2 = oid[i];
                        /*lista de diagnosticos especificos que se encuentran en la vista*/
                        t = document.getElementsByName("txtoid[]");
                        for(var l = 1; l<=t.length ; l++){
                           oida = document.getElementById("oid"+l).value;
                           if(oid2 == oida){
                               document.getElementById("seleccionc"+l).checked = true;
                           }
                        }
                     }
                   }
                   function seleccion(){
                       var tama =document.getElementsByName("txtoid[]");
                       if(document.getElementById("selecTodo").checked){
                           for(var i = 1; i <= tama.length; i++){
                               document.getElementById("seleccionc"+i).checked = true;
                           }
                       }else{
                           for(var i = 1; i <= tama.length; i++){
                              document.getElementById("seleccionc"+i).checked = false;
                           }
                       }
                   }
                
                
        </script>
    </head>
    <body onload="datosD();">
        <div align="center" style="border-radius: 5px 5px 0px 0px;background:linear-gradient(#e8eaeb, #B5B5B5);height:10%;width:100%;">
            <table style="width:100%; height:10%;">
                <tr>
                    <td width="88.3%" >
                        <div style="padding:1.5%;"><b style="">RIESGOS ESPECIFICOS DE LA CIRUGIA, PROCEDIMENTO O TRATAMIENTO</b></div>
                    </td>
                    <td>
                        <input type="text" name="" value="" id="buscar" placeholder="BUSCAR" onKeyUp="buscarD();"/>
                    </td>
                </tr>
            </table>
        </div>
        <div style='overflow-y: scroll;height:75%;'>
            <div id="datosd"></div>
        </div>
        <div style="border-radius: 0px 0px 5px 5px;background:linear-gradient(#e8eaeb, #B5B5B5);height:15%;width:100%;">
            <div style="padding:1%;">
                <table style="font-size:80%;width:100%" >
                    <tr>
                        <td style="width:10%" >
                            <input type="button" value="Nuevo Riesgo" class="white" onclick="nuevoD();"/>
                        </td>
                        <td style="width:45% ">
                            <div id="nuevoD" ></div>
                        </td>
                        <!--<td style="width:20%;">
                            <input type="text" name="txtBuscar" value="" id="buscar" style="width:100%"/>
                        </td>-->
                        <td align="right" width="8%">
                            <!--<input type="button" value="Buscar" class="white" onclick="validarBuscar();"/>
                            <input type="button" value="Cancelar" class="white" onclick="cancelar();"/>-->
                            <input title="Seleccionar" type="checkbox" name="selecTodo" value="" title="Seleccionar Todo" id="selecTodo" onchange="seleccion();"/>
                        </td>
                        <td align="right" width="4%">
                            <input type="button" class="white" value="Agregar" onclick="agregarD();"/>
                        </td>
                    </tr>
                </table>
            </div>
         </div>
        <input type="hidden" id="listaoid" name="txtlistaoid" value="<?php echo$_REQUEST['listaoid'] ?>" />
         <input type="hidden" id="pos" name="txtlistaoid" value="<?php echo$_REQUEST['pos'] ?>" />
    </body>
    
    